class BillingProfile < ActiveRecord::Base
  # ?????? history   don't delete any profile   just set canceld status
  has_many :billing_credit_cards, :dependent => :destroy, :order => 'id DESC'
    # belongs_to :billing_order  

  # validates_associated :billing_profile

  # # create new account
  #   attr_accessor :card_number, :card_verification, :first_name, :last_name, :zipcode, 
  #                 :expires_at_month, :expires_at_year,
  #                 :card_type

    # # before_create :create_credit_card
    # 
    # # # before_validation :credit_card
    # # validate :credit_card_update, :on => :update, :if => :update_action?
    # 
    # after_create :credit_card_store
    # # validate :credit_card_store
    # # before_update :credit_card_update
    # 
    # before_destroy :credit_card_delete


    # Validations -----------------------------------------------------
    validates_presence_of   :user_id
                            
    validates_uniqueness_of :user_id
    # -----------------------------------------------------------------

    #----- Act as FINITE STATE MACHINE -------------
      acts_as_state_machine :initial => :inactive, :column => :status

      state :inactive, :column => :status
      state :active, :column => :status
      state :canceled, :column => :status

      event :activate do
        transitions :from => :inactive, :to => :active
      end

      event :cancel do
        transitions :from => :active, :to => :canceled
      end
      
      # reference of statuses for this model
      def self.statuses
        [RefActionStatus::ACTIVE, RefActionStatus::INACTIVE]
      end
    #-----------------------------------------------
end